import urllib.request 
import re
# # 浏览器伪装
# opener = urllib.request.build_opener()
# # 浏览器标识
# UA=("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36 Edg/80.0.361.69")
# opener.addheaders =[ UA] 
# urllib.request.install_opener(opener )
# data = urllib.request.urlopen("http://www.jd.com").read().decode("utf-8","ignore")
# print(len(data))


# python 随机数
import random 
uapools=[
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36 Edg/80.0.361.69"
]
def UA():
  opener = urllib.request.build_opener()
  nowua = random.choice(uapools)
  ua = ("User-Agent", nowua )
  opener.addheaders = [ua]
  urllib.request.install_opener(opener)
  print("当前用户标识",nowua )
#  嗅事百科 的网站 ，有反扒阻止
url = "https://www.qiushibaike.com"

for i in range(0,10):
  UA()
  data=urllib.request.urlopen(url).read().decode("utf-8","ignore")
  print(len(data))


